$(function(){
	getPic();
	$("#identyCardPathInput").change(function(){
		ajaxfileuploadUtil(this,"pic",picImagEdit);
	});
	/*$('#hold').tap(function() {
		questionAdd();
	});*/
	var bl = localStorage.getItem("opration");
	if(null != bl){
		localStorage.removeItem("opration");
		bl = null;
		$('.icon-peo').parent().click();
	}
});
function initUserData(){
	$.ajax({
		type : 'POST',
		async : false,
		data : {usersid:userid},
		url : server_url+'rest/frontUser/getFrontUser.do?ran='+Math.random(),
		dataType : 'json',
		success : function(data) {
			var suppluName = data.data.supplyName;
			if(suppluName !=null){
				$("#realName").text(suppluName);
			}
			
		}
	});
	initDatas('01','',initNotPayOrderNum);
	initDatas('','01',intiNotReciveOrderNum);
}

var initNotPayOrderNum = function(num){
	if(num ==0){$("#orderStatus1 span").removeAttr('class');return;}
	$("#orderStatus1 span").text(num);
}
var intiNotReciveOrderNum = function(num){
	if(num ==0){$("#orderStatus2 span").removeAttr('class');return;}
	$("#orderStatus2 span").text(num);
}
function initDatas(orderStatus,shipStatus,fn){
	$.ajax({
		url:server_url+"rest/sellerOrder/getOrders.do",
		data:{sellerUserId:userid,orderStatus:orderStatus,shipStatus:shipStatus,rand:Math.random()},
		success:function(data){
			fn(data.data.length);
		}
	});
}
function questionAdd(){
	var question=$("#question").val();
	if(empty(question)){
		easyAlert("内容不能为空!");
		return;
	}
	if(question.length > 140){
		easyAlert("内容不能超过140个字");
		return;
	}
	if(!checkQuest(question)){
		easyAlert("只允许输入中文");
		return;
	}
	if(question !=""){
			$("#problem").css({"display":"none"});
	}
	 $.ajax({
         type : "POST",
         dataType : "json",
         url :server_url+'rest/suggest/suggestAdd.do?ran='+Math.random(),
         data : {question:question,sort:3},
         contentType : "application/x-www-form-urlencoded; charset=utf-8",
         success : function(data) {
        	 if(data.retCode == "0000"){
        		 easyAlert("提交成功!");
        	 }
         }
         });
}


function checkQuest(question){
	var reg=/([\u4E00-\u9FA5]|[\uFE30-\uFFA0])+/;
	 return reg.test(question);
}
function getPic(){
	$.ajax({
		type : 'POST',
		async : false,
		data : {userId:userid},
		url : server_url+'rest/frontUser/getPic.do?ran='+Math.random(),
		success : function(data) {
			if (data.retCode == "0000") {
				var pasteData = data.data;
				$("#compName").text(pasteData.buyerInfoVo.compName);
				if(pasteData.picPath != null && pasteData.picPath !=""){
					$("#picPath").attr("src",pasteData.picPath);
					$("#picPath").val(pasteData.picPath);
				}else{
					$("#picPath").attr("src","img/user.png");
				}
				
			} else{
				easyAlert("操作失败");
			}
		}
	});
}

function picImagEdit(data,input){
	var id = $(input).attr("id").substring(11);
	$.ajax({
		type:"POST",
		async : false,
		data:{identyCardPath:data.data,userId:userid},
		url : server_url+'rest/frontUser/updatePic.do?ran='+Math.random(),
		success:function(data){
			if(data.retCode == "0000"){
				var path = data.data;
				$("#"+id).siblings("input[type=hidden]").val(path);
				$("#"+id).siblings("img").attr("src",path);
			}else{
			easyAlert("网络异常,请稍后再试");
			}
		},
	});
}

function setting(){
	window.location=server_url+"setting.do";
}
function shipped(){
	localStorage.setItem('daifu','daifu');
	localStorage.setItem('order','order');
	window.location=server_url+"shipped.do";
}
function pending(){
	localStorage.setItem('daifa','daifa');
	localStorage.setItem('order1','order1');
	window.location=server_url+"pending.do";
}
function logout(){
	confirmUtil("您确定要退出吗？",function(r){
		if(r){
			localStorage.removeItem("username");
			window.location=server_url+"login.do";
		}
	});
}
function toBuyerLogin(){
	window.location=server_url+"buyerLogin.do";
}
var toCall = function(){
	window.location.href="tel:010-57019707";
}
function toOnlinePay(){
	$.ajax({
		url:server_url+"rest/supply/supply.do",
		type:"POST",
		data:{userid:userid,rand:Math.random()},
		error:function(){alert(contants.systemError);},
		success:function(data){
			if(data.data.isOpenOnlinPay=='1'){
				easyAlert("您已经申请了在线支付！");
				return;
			}else{
				$.ajax({
					url:server_url+"rest/yjf/supplyRegiste.do",
					type:"get",
					data:{userid:userid,rand:Math.random()},
					error:function(){alert(contants.systemError);},
					success:function(data){
						if(data.retCode == '0000'){
							window.location = data.data;
						}
						
					}
				});
			}
		}
	});
	
}
//改变卖家是否开通在线支付状态
function changeSupplyStatus(){
	$.ajax({
		url:server_url+"rest/supply/updateSupplyByUserId.do",
		type:"get",
		data:{userId:userid},
		error:function(){contants.systemError},
		success:function(data){
			
		}
	})
}







